clear all;close all;clc

Subjects = {'A63','A64','A68','A69','A70','A72','A73','A74','A75','A76','A77','A78','A79','A80','A81','A82'};


Sessions = 1:20;
hiddenlayers = 7;
K_fold = 10;
fingers = 'abcde';
finger_names = {'Thumb';'Index';'Middle';'Ring';'Pinky'};
f_low = 0.1;
f_high = 30;
FS = 198.5;
[b,a]=butter(3,[f_low f_high]./(FS./2));

for isubject = 1:length(Subjects)
    Sub = Subjects{isubject}

    All_vectors{1} = [];
    All_vectors{2} = [];
    All_vectors{3} = [];
    All_vectors{4} = [];
    All_vectors{5} = [];
    for Session =Sessions
        for ifinger = 1:5
            filename = ['Save_RMS_up\' Sub(2:end) '_' num2str(Sessions(Session)) fingers(ifinger) '.mat']; %read or import
            load(filename);
            All_vectors{ifinger}=[All_vectors{ifinger}
                EMG_rms'];

            clear EMG_rms;
            pause(0.1)
        end
    end

    Xall = [];
    for i=1:5
        Xall=[
            Xall
            All_vectors{i} ];

    end
    grand_avg = mean(Xall);

    for i=1:5
        All_vectors{i}=All_vectors{i}-grand_avg;
    end

    out=f_runNN_Kfold(hiddenlayers,All_vectors,K_fold);

    CM = out.CM;
    PC= out.PC*100
%     pci(isubject) = f_confid_I(20*20*5,PC(isubject)/100,0.05)

    eval(['save Save_EMG_NN_result\' Sub(2:end) '_CM PC CM'  ])


end
f3 = figure;
bar((1:length(Subjects)),PC);
